//
//  HomePageViewController.m
//  CenturyInterconnection
//
//  Created by Tian Wei You on 16/4/5.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "HomePageViewController.h"
#import "HomepageTableViewCell.h"
#import "LeftMenuViewController.h"
#import "SecondLevelMenuViewController.h"
#import "RightMenuViewController.h"
#import "HomepageCollectionTableViewCell.h"
#import "ProductListViewController.h"
#import "RegisterViewController.h"
#import "ShoppingCarViewController.h"
#import "CommodityDetailsTableViewController.h"
#import "SDCycleScrollView.h"
#import "RefreshProductListViewController.h"
#import "HomepageCollectionViewCell.h"
#import "XXNavigationController.h"
#import "WishListViewController.h"
#import "CurrencyConversionViewController.h"
#import "PrivacyStatementViewController.h"
#import "ContactUsViewController.h"
#import "NewLeftMenuViewController.h"
#import "JPUSHService.h"


#define STOREAPPID @"1135813088" //商城的appID

#define HomepageCell  @"HomepageCollectionViewCell"


@interface HomePageViewController ()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate,LeftMenuViewControllerDelegate,RightMenuViewControllerDelegate,HomepageCollectionTableViewCellDelegate,SDCycleScrollViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,SlideNavigationControllerDelegate,SecondLevelMenuViewControllerDelegate,UITextFieldDelegate>

@property(nonatomic,strong) UITableView * tableView;

@property(nonatomic,strong) NSMutableArray * allDatas;
@property(nonatomic,strong) NSMutableArray * allListDatas;
@property(nonatomic,strong) NSMutableArray * threeImagesDatas;

@property(nonatomic,strong) NSString *ListStr;

@property(nonatomic,strong) UITextField *searchTextField;

@property(nonatomic,strong) UILabel * messageLabel;


@property(nonatomic,assign) int pages;



@property(nonatomic,retain)NSArray * searchStrArray;

@property (nonatomic,retain) UIView * searchView;

<<<<<<< HEAD
@property (nonatomic,retain) NSArray * brandArray;
=======
>>>>>>> parent of 58ffaa4... init
@end



@implementation HomePageViewController

-(UITableView *)tableView{
    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];
    [JPUSHService setBadge:0];
    

    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,ACTUAL_HEIGHT(50), KScreenWidth, KScreenHeight-ACTUAL_HEIGHT(90)) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
    }
    return _tableView;
}

- (UILabel *)messageLabel{
    
    if(!_messageLabel){
        _messageLabel=[[UILabel alloc] init];
        _messageLabel.frame = CGRectMake(ACTUAL_WIDTH(-15),ACTUAL_HEIGHT(5), ACTUAL_WIDTH(20), ACTUAL_HEIGHT(20));
        _messageLabel.backgroundColor=RGBACOLOR(206, 207, 208, 1);
        _messageLabel.layer.cornerRadius = 10;
        _messageLabel.layer.masksToBounds = YES;
        _messageLabel.textAlignment=1;
        _messageLabel.textColor=[UIColor blackColor];
        [_messageLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
    }
    return _messageLabel;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"MainPage"];//("PageOne"为页面名称，可自定义)
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"MainPage"];
}


#pragma mark - viewDidLoad
- (void)viewDidLoad {
    
    [super viewDidLoad];
    //检测更新
    [self hsUpdateApp];
    
    self.allDatas=[NSMutableArray array];
    self.threeImagesDatas=[NSMutableArray array];
    self.allListDatas=[NSMutableArray array];
    
<<<<<<< HEAD
    self.title=@"ShoesJoy";
    _brandArray = [NSArray arrayWithObjects:@"AIR JORDAN 12",@"YEEZY BOOST 350",@"ADIDAS NMD RUNNER",@"NIKE AIR HUARACHE",@"NIKE AIR MAX 90",@"NIKE ROSHE ONE FLYKNIT", nil];
=======
    self.title=@"AirClub";
    
>>>>>>> parent of 58ffaa4... init
    
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(letSelfToRefresh) name:@"letHomePageVCToRefresh" object:nil];
    
    
    
    [[NSUserDefaults standardUserDefaults]setObject:@"USD" forKey:@"CURRENCY"];
    
    //
    self.pages=1;
    
    
    [self createNavLeftBtn];
    
    //
    [self getCookie];
    
    
    [self setupRefresh];
    
    [self.view addSubview:self.tableView];
    
    //HomePage主页显示
    [self makeView];
    
    [self.tableView registerClass:[HomepageTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.tableView registerClass:[HomepageCollectionTableViewCell class] forCellReuseIdentifier:@"cell2"];
    
    
    
    [UserSession instance].isGotoPayment=NO;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    [self getShopCartData];
    
    if(self.isOpenSearch){
        [self.searchTextField becomeFirstResponder];
    }
    
    
    
}

<<<<<<< HEAD
//- (void)viewWillDisappear:(BOOL)animated{
//    [self.searchTextField resignFirstResponder];
//}
=======
- (void)viewWillDisappear:(BOOL)animated{
    [self.searchTextField resignFirstResponder];
}
>>>>>>> parent of 58ffaa4... init

-(void)createNavLeftBtn
{
    UIButton *leftbutton  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [leftbutton setImage:[UIImage imageNamed:@"nav_menu"] forState:UIControlStateNormal];
    [leftbutton addTarget:self action:@selector(goToNewLeftVC) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftbutton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
}
-(void)goToNewLeftVC
{
    NewLeftMenuViewController * newVC = [[NewLeftMenuViewController alloc]init];
    [[SlideNavigationController sharedInstance] pushViewController:newVC animated:YES];
}

#pragma mark - 网络请求
//获取cookie值
-(void)getCookie{
    
    //http://viprunningonline.com/api/index.php?main_page=zenid
    
    NSString * urlStr=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
    
    NSDictionary*params=@{@"main_page":@"zenid"};
    
    
    AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
    [manager GET:urlStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSString * number=[NSString stringWithFormat:@"%@",responseObject[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            [UserSession instance].cookie=responseObject[@"data"][@"zenid"];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        //NSLog(@"Error: %@", error);
        
        [JRToast showWithText:@"Connection timeout,please check the network." bottomOffset:70*KScreenWidth/320 duration:3.0f];
    }];
    
    
}

//获取home数据
//导航栏数据
-(void)getShopCartData{
    
    if([UserSession instance].cookie ){
        
        // http://viprunningonline.com/api/index.php?main_page=shopping_cart
        
        NSString * urlStr1=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
        
        NSString * zenidStr = [UserSession instance].cookie;
        
        NSDictionary * params1=@{@"main_page":@"shopping_cart",
                                 @"zenid":zenidStr};
        
        HttpManager * manager1=[[HttpManager alloc] init];
        
        [manager1 getDataFromNetworkWithUrl:urlStr1 parameters:params1 compliation:^(id data, NSError *error) {
            
            //NSLog(@"getShopCartData %@",data);
            
            NSString * statusnumber=[NSString stringWithFormat:@"%@",data[@"status"]];
            
            if ([statusnumber isEqualToString:@"1"]) {
                
                NSInteger  countNum = [data[@"data"][@"cart"] count];
                
                [self makeNaviButton:countNum];
                
            }
        }];
    }
    
}

//首页三张纸
- (void)getHomeIndexBannerData{
    
    //http://viprunningonline.com/api/index.php?main_page=index_banner
    NSString*urlStrr=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
    NSDictionary*paramss=@{@"main_page":@"index_banner"};
    HttpManager*managerr=[[HttpManager alloc] init];
    [managerr getDataFromNetworkWithUrl:urlStrr parameters:paramss compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            
            self.threeImagesDatas=data[@"data"];
            [self.tableView reloadData];
        }else{
            self.tableView.allowsSelection = NO;
        }
    }];
}

//推荐产品列表
- (void)getFeaturedProductsData{
    
    // http://viprunningonline.com/api/index.php?main_page=featured_products
    NSString*urlStr=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
    NSDictionary*params=@{@"main_page":@"featured_products"};
    HttpManager*manager=[[HttpManager alloc] init];
    [manager getDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            
            self.allDatas=data[@"data"][@"products_list"];
        }
    }];
}



#pragma mark - view
//导航栏
-(void)makeNaviButton:(NSInteger)count{
    
    if(count > 0 ){
        self.messageLabel.text= [NSString stringWithFormat:@"%ld",(long)count] ;
        [[SlideNavigationController sharedInstance].rightBarButtonItem.customView addSubview:self.messageLabel];
    }else{
        [self.messageLabel removeFromSuperview];
        self.messageLabel = nil;
    }
    
}

//主页显示
-(void)makeView{
    self.view.backgroundColor = RGBACOLOR(255, 255, 255, 1);
    
    UIView *headerBGView=[[UIView alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(0), 64, KScreenWidth, ACTUAL_HEIGHT(50))];
    headerBGView.backgroundColor=RGBACOLOR(255, 255, 255, 1);
    [self.view addSubview:headerBGView];
    
    //search bar
    _searchTextField=[[UITextField alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), ACTUAL_HEIGHT(5), ACTUAL_WIDTH(300), ACTUAL_HEIGHT(50))];
    _searchTextField.placeholder=@"SEARCH";
    _searchTextField.font = FONT_SYSTEM_24;
    _searchTextField.delegate = self;
    _searchTextField.textColor = [UIColor blackColor];
    _searchTextField.returnKeyType = UIReturnKeySearch;
    [headerBGView addSubview:_searchTextField];
    
    //searchbutton
    UIButton *searchButton=[[UIButton alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(325), ACTUAL_HEIGHT(0), ACTUAL_WIDTH(50), ACTUAL_HEIGHT(50))];
    [searchButton addTarget:self action:@selector(gotoSearchView) forControlEvents:UIControlEventTouchUpInside];
    [headerBGView addSubview:searchButton];
    
    //searchImageview
    UIImageView *searchImageView=[[UIImageView alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(335), ACTUAL_HEIGHT(20), ACTUAL_WIDTH(21), ACTUAL_HEIGHT(21))];
    [searchImageView setImage:[UIImage imageNamed:@"menu_search"]];
    [headerBGView addSubview:searchImageView];
    
    
    NSArray *images=@[@"http://image16-c.poco.cn/mypoco/myphoto/20160504/16/17398204620160504165728027.jpg?749x80_120",
                      @"http://image16-c.poco.cn/mypoco/myphoto/20160504/16/17398204620160504165728027.jpg?749x80_120",
                      @"http://image16-c.poco.cn/mypoco/myphoto/20160504/16/17398204620160504165728027.jpg?749x80_120"];
    
    //scrollview
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, KScreenHeight-ACTUAL_HEIGHT(40), KScreenWidth, ACTUAL_HEIGHT(40)) imagesGroup:images];
    cycleScrollView.delegate = self;
    cycleScrollView.autoScrollTimeInterval = 3.0;
    [cycleScrollView.pageControl removeFromSuperview];
    [self.view addSubview:cycleScrollView];
    
}


#pragma mark --- textFieldDelegateMethod
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    _searchStrArray = [NSArray arrayWithObjects:@"yeezy",@"750",@"550",@"350",@"max 2017",@"nmd",@"max 90",@"boost", nil];
    _searchView = [[UIView alloc]init];
    _searchView.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:0.96];
    [self.view addSubview:_searchView];
    [_searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_searchTextField.mas_bottom).offset(-4.95);
        make.left.offset(0);
        make.right.offset(0);
        make.height.equalTo(self.view.mas_height).multipliedBy(0.2);
    }];
    UIImageView * imgView = [[UIImageView alloc]init];
    imgView.image = [UIImage imageNamed:@"search_icon"];
    [_searchView addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(3);
        make.left.offset(5);
        make.width.equalTo(_searchView.mas_height).multipliedBy(0.2);
        make.height.equalTo(_searchView.mas_height).multipliedBy(0.2);
    }];
    UILabel * label = [[UILabel alloc]init];
    label.text = @"HOT SEARCHES";
    label.textColor = [UIColor grayColor];
    [_searchView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgView.mas_right).offset(5);
        make.centerY.equalTo(imgView.mas_centerY);
        make.width.equalTo(_searchView.mas_width).multipliedBy(0.5);
        make.height.equalTo(_searchView.mas_height).multipliedBy(0.15);
    }];
    
    for (int i = 0; i < _searchStrArray.count; i++) {
        UIButton * searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        searchBtn.backgroundColor = [UIColor whiteColor];
        [searchBtn setTitle:_searchStrArray[i] forState:UIControlStateNormal];
        if (KScreenWidth == 320) {
            searchBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        }else{
            searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        }
        searchBtn.layer.cornerRadius = 8.0;
        searchBtn.layer.shadowColor = [[UIColor colorWithWhite:0.3 alpha:0.5]CGColor];
        [searchBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        searchBtn.tag = i;
        [searchBtn addTarget:self action:@selector(searchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_searchView addSubview:searchBtn];
        [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imgView.mas_bottom).offset(8+i/5*(KScreenHeight*0.2*0.3+8));
            make.left.offset(5+i%5*((KScreenWidth-30)/5+5));
            make.width.offset((KScreenWidth-30)/5);
            make.height.equalTo(_searchView.mas_height).multipliedBy(0.3);
        }];
    }
}
-(void)searchBtnClick:(UIButton *)button
{
    RefreshProductListViewController *vc=[[RefreshProductListViewController alloc]init];
    [_searchView removeFromSuperview];
    vc.keywordStr=_searchStrArray[button.tag];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == _tableView) {
        if (_searchView) {
            [_searchView removeFromSuperview];
            [self.view endEditing:YES];
        }
        
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (_searchTextField.text.length==0) {
        [JRToast showWithText:@"Please input search content！"];
    }else{
        RefreshProductListViewController *vc=[[RefreshProductListViewController alloc]init];
        vc.keywordStr=_searchTextField.text;
        [self.navigationController pushViewController:vc animated:YES];
    }
    return YES;
}

#pragma mark  - 刷新
//集成刷新控件

- (void)setupRefresh{
    
    //1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    //[self.tableView addHeaderWithTarget:self action:@selector(headerRereshing)];
    // dateKey用于存储刷新时间，可以保证不同界面拥有不同的刷新时间
    
    [self.tableView addHeaderWithTarget:self action:@selector(headerRereshing) dateKey:@"table"];
#warning 自动刷新(一进入程序就下拉刷新)
    [self.tableView headerBeginRefreshing];
}

- (void)headerRereshing{
    
    [self getShopCartData];
    [self getHomeIndexBannerData];
    [self getFeaturedProductsData];
    
    [self.tableView reloadData];
    [self.tableView headerEndRefreshing];
}

#pragma mark --- 通知让右侧栏点击退出登录返回时刷新界面
-(void)letSelfToRefresh
{
    [self setupRefresh];
}


#pragma mark - tableView属性设置
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 7;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==6) {
        return ACTUAL_HEIGHT(240)*(self.allDatas.count)/2;
    }else{
        return ACTUAL_HEIGHT(303);
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"celll"];
    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];
    [JPUSHService setBadge:0];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"celll"];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    
    if (indexPath.row < 6) {
        
        HomepageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (self.threeImagesDatas.count>0) {
            [cell.titleImageView sd_setImageWithURL:[NSURL URLWithString:self.threeImagesDatas[indexPath.row][@"image"]] placeholderImage:nil];
        }
        return cell;
        
    }else{
        
        HomepageCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
        [cell getValue:self.allDatas];
        cell.delegate=self;
        return cell;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];
    [JPUSHService setBadge:0];


    NSString * cateeName = self.threeImagesDatas[indexPath.row][@"main_page"];
    NSString * cPath = [NSString stringWithFormat:@"%ld",[self.threeImagesDatas[indexPath.row][@"params"][@"cPath"]integerValue]];
    NSString * cPathStr = self.threeImagesDatas[indexPath.row][@"params"][@"cPath"];
    
    if(indexPath.row < 6)
    {
        ProductListViewController * productlistVC = [[ProductListViewController alloc] init];
        //1
        if ([cateeName isEqualToString:@"index"]&&[cPath isEqualToString:@"103"]) {
            
            productlistVC.ListOfSpeciesStr = @"products_list";
            productlistVC.categories_name = @"AIR JORDAN 12";
            productlistVC.cPathStr = self.threeImagesDatas[indexPath.row][@"params"][@"cPath"];

        }
        //2
        if ([cateeName isEqualToString:@"product_info"]&&[cPathStr isEqualToString:@"120_121_122"]){
            
            productlistVC.ListOfSpeciesStr = @"products_list";
            productlistVC.categories_name = @"YEEZY BOOST 350";
            productlistVC.cPathStr = self.threeImagesDatas[indexPath.row][@"params"][@"cPath"];

        }
        //3
        if ([cateeName isEqualToString:@"index"]&&[cPath isEqualToString:@"217"]){
            
            productlistVC.ListOfSpeciesStr = @"products_list";
            productlistVC.categories_name = @"ADIDAS NMD RUNNER";
            
            productlistVC.cPathStr = self.threeImagesDatas[indexPath.row][@"params"][@"cPath"];
            
        }
        //4
        if ([cateeName isEqualToString:@"product_info"]&&[cPathStr isEqualToString:@"144_145_159"]){
            
            productlistVC.ListOfSpeciesStr = @"products_list";
            productlistVC.categories_name = @"NIKE AIR HUARACHE";
            
            productlistVC.cPathStr = self.threeImagesDatas[indexPath.row][@"params"][@"cPath"];
            
            
        }
        //5
        if ([cateeName isEqualToString:@"index"]&&[cPath isEqualToString:@"147"]){
            
            productlistVC.ListOfSpeciesStr = @"products_list";
            productlistVC.categories_name = @"NIKE AIR MAX 90";
            
            productlistVC.cPathStr = self.threeImagesDatas[indexPath.row][@"params"][@"cPath"];
            
        }
        //6
        if ([cateeName isEqualToString:@"index"]&&[cPath isEqualToString:@"164"]){
            
            productlistVC.ListOfSpeciesStr = @"products_list";
            productlistVC.categories_name = @"NIKE ROSHE ONE FLYKNIT";
            
            productlistVC.cPathStr = self.threeImagesDatas[indexPath.row][@"params"][@"cPath"];
            
        }
        [[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:productlistVC withCompletion:^{}];
    }
    
    else
    {
        if ([cateeName isEqualToString:@"product_info"]){
            
            CommodityDetailsTableViewController *vc= [[CommodityDetailsTableViewController alloc] init];
            vc.idStr=self.threeImagesDatas[indexPath.row][@"params"][@"products_id"];
            [[SlideNavigationController sharedInstance] switchToViewController:vc withCompletion:nil];
            return;
        }
    }
    
    
}

#pragma mark - 实现cell中委托首页跳转详情界面的方法
-(void)cellOfcollectionselected:(NSString *)productId{
    CommodityDetailsTableViewController *vc=[[CommodityDetailsTableViewController alloc]init];
    vc.idStr=productId;
    [self.navigationController pushViewController:vc animated:YES];
}



#pragma mark - 滚动tableview的时候收起键盘
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
}

#pragma mark - 跳转搜索页面
-(void)gotoSearchView{
    if (_searchTextField.text.length==0) {
        [JRToast showWithText:@"Please input search content！"];
    }else{
        RefreshProductListViewController *vc=[[RefreshProductListViewController alloc]init];
<<<<<<< HEAD
        NSDictionary *dict = @{@"index" : _searchTextField.text};
        [MobClick event:@"SearchClick" attributes:dict];
=======
>>>>>>> parent of 58ffaa4... init
        vc.keywordStr=_searchTextField.text;
        [self.navigationController pushViewController:vc animated:YES];
    }
}



//#pragma mark - 自动刷新(一进入程序就下拉刷新)
//- (void)addHeader
//{
//    __unsafe_unretained typeof(self) vc = self;
//    // 添加下拉刷新头部控件
//    [self.collectionView addHeaderWithCallback:^{
//        vc.pages=1;
//        vc.allListDatas=[NSMutableArray array];
//
//        [vc getListDatas];
//
//    } dateKey:@"collection"];
//    // dateKey用于存储刷新时间，也可以不传值，可以保证不同界面拥有不同的刷新时间
//
//    #warning 自动刷新(一进入程序就下拉刷新)
//    [self.collectionView headerBeginRefreshing];
//}
//
//- (void)addFooter
//{
//    __unsafe_unretained typeof(self) vc = self;
//    // 添加上拉刷新尾部控件
//    [self.collectionView addFooterWithCallback:^{
//        vc.pages++;
//
//        // 进入刷新状态就会回调这个Block
//        [vc getListDatas];
//
//        // 模拟延迟加载数据，因此2秒后才调用（真实开发中，可以移除这段gcd代码）
//    }];
//}



#pragma mark - SlideNavigationController Methods
- (BOOL)slideNavigationControllerShouldDisplayLeftMenu
{
    return NO;
}

- (BOOL)slideNavigationControllerShouldDisplayRightMenu
{
    [_searchView removeFromSuperview];
    return YES;
}


#pragma mark - 左侧栏跳转回来并前让搜索栏变成第一响应事件
-(void)delegateForSearchBecomeFirst{
    NSLog(@"1111");
    [self.searchTextField becomeFirstResponder];
}


//#pragma mark - UITextFieldDelegate
//
//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
//{
//    return YES;
//}
//
//- (BOOL)textFieldShouldReturn:(UITextField *)textField
//{
//    return YES;
//}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)hsUpdateApp
{
    //2先获取当前工程项目版本号
    NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion=infoDic[@"CFBundleShortVersionString"];
    
    //3从网络获取appStore版本号
    NSError *error;
    NSData *response = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",STOREAPPID]]] returningResponse:nil error:nil];
    if (response == nil) {
        NSLog(@"你没有连接网络哦");
        return;
    }
    NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
    if (error) {
        NSLog(@"hsUpdateAppError:%@",error);
        return;
    }
    NSArray *array = appInfoDic[@"results"];
    NSDictionary *dic = array[0];
    NSString *appStoreVersion = dic[@"version"];
    //打印版本号
    NSLog(@"当前版本号:%@\n商店版本号:%@",currentVersion,appStoreVersion);
    //    4当前版本号小于商店版本号,就更新
    if([currentVersion floatValue] < [appStoreVersion floatValue])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Version update" message:[NSString stringWithFormat:@"New version detected(%@),Whether to update?",appStoreVersion] delegate:self cancelButtonTitle:@"Cancel"otherButtonTitles:@"Update",nil];
        [alert show];
    }else{
        NSLog(@"版本号好像比商店大噢!检测到不需要更新");
    }
    
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //    5实现跳转到应用商店进行更新
    if(buttonIndex==1)
    {
        //6此处加入应用在app store的地址，方便用户去更新，一种实现方式如下：
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", STOREAPPID]];
        [[UIApplication sharedApplication] openURL:url];
    }
}
@end
